<?php

namespace app\api\controller\v1;

use yifang\facade\App;

class Test
{
    /**
     * 测试接口
     * @path /api/v1/test
     * @header string version 版本 require
     * @method get
     * @param string name 名称 require
     * @param string age 年龄 optional
     * @return {asd:2}
     */
    public function index(){
        $getYifangPath=App::getYifangPath();
        dump($getYifangPath,3);exit;
        echo "版本1：测试";
    }

    /**
     * @path /api/test/db
     * 测试数据库
     */
    public function db(){

//        $condition=array();
//        $condition[]=array(
//            "id","=",2,
//        );
//        $result=db_manage()->table("yifang_friend_link")->where($condition)->field("id,status")->find();

//        $data=array(
//            array(
//                "linkName"=>"2\\22",
//                "linkUrl"=>"fff",
//                "description"=>"333",
//            ),
//        );
//        $result=db_manage()->table("yifang_friend_link")->insertAll($data);

//        $data=array();
//        $data["id"]=24;
//        $data["linkName"]=444555;
//        $result=db_manage()->table("yifang_friend_link")->update($data);

//        $data=array();
//        $data["id"]=24;
//        $result=db_manage()->table("yifang_friend_link")->delete($data);

//        $fields=array();
//        $fields[]="linkName";
//        $fields[]="linkUrl";
//        $result=db_manage()->table("yifang_friend_link")->field("linkName,linkUrl")->selectInsert($fields,"yifang_friend_link_copy1");

//        $paginate=db_manage()->table("yifang_friend_link")->field("linkName,linkUrl")->paginate(2);
//        $data=$paginate->data();
//        $drender=$paginate->render();

//        $condition=0;
//        $result=db_manage()->table("yifang_friend_link")->when($condition, function ($query) {
//            // 满足条件后执行
//            $query->where('id', '>=', 5)->limit(5);
//        }, function ($query) {
//            // 满足条件后执行
//            $query->where('id', '<', 5)->limit(5);
//        })->select();

//        $result=db_manage()->table("yifang_friend_link")->where('id', 3)->find();

//        $result=db_manage()->table("yifang_friend_link")->where('status',1)->chunk(2, function($data) {
//            foreach ($data as $user) {
//                echo $user["linkName"].PHP_EOL;
//            }
//        });

//        $data=array();
//        $data["id"]="25";
//        $data["linkName"]="测试";
//        $result=db_manage()->table("yifang_friend_link")->save($data);

//        $result=db_manage()->table("yifang_friend_link")->where('id',28)->exp('linkUrl','UPPER(linkUrl)')->update();

//        $result=db_manage()->table("yifang_friend_link")->where('id',28)->inc('sortWeights')->update();

//        $result=db_manage()->table("yifang_friend_link")->count();

//        $paginate=db_manage()->table("yifang_friend_link")->where('status',1)->order('id', 'desc')->paginate(1)->each(function($item, $key){
//            $item['nickname'] = 'think';
//            return $item;
//        });
//
//        $result=$paginate->data();
//        $drender=$paginate->render();

//        $paginate=db_manage()->table("yifang_friend_link")->where('status',1)->order('id', 'desc')->paginateX(1,"id","asc")->each(function($item, $key){
//            $item['nickname'] = 'think';
//            return $item;
//        });
//        $result=$paginate->data();
//        $drender=$paginate->render();

//        $result=db_manage()->table("yifang_friend_link")->whereYear('addTime')->select();

//        $user=array();
//        $user['linkName'] = '1231';
//        $user['description'] = [
//            'email'    => 'thinkphp@qq.com',
//            'nickname' => '流年',
//        ];
//        $result=db_manage()->table("yifang_friend_link")->json(['description'])->insert($user);

//        $result = db_manage()->name('friend_link')->json(['description'])->where('description->>email','thinkphp@qq.com')->fetchSql()->find();

//        $data=array();
//        $data['description->email'] = '1724827556@qq.com';
//        $result=db_manage()->name('friend_link')->json(['info'])->where('id',39)->update($data);

//        $subQuery=db_manage()->name('friend_link')->field("id,status,linkName")->buildSql();
//        $result=db_manage()->table($subQuery . ' a')->where('a.linkName', 'like', '%用户%')->fetchSql(false)->select();

//        $result=db_manage()->name('friend_link')->where('id', '=',39)->select();

//        db_manage()->transaction(function ($connect) {
//            $user=array();
//            $user['linkName'] = '1231';
//            $user['description'] = [
//                'email'    => 'thinkphp@qq.com',
//                'nickname' => '流年',
//            ];
//            $result=$connect->table("yifang_friend_link")->json(['description'])->insert($user);
//        });

//        $result=db_manage()->query("select * from yifang_friend_link where id=:id", ['id' => 39]);

        dd("执行完毕");

    }
}
